/*
 * 作者:熊猫
 * 日期:2017 - 3 - 16 4 - 4 - 27
 *
 */

package net.lainiao.morethread.Chapter7.demo3;

import net.lainiao.morethread.MyDateUtils;

import java.util.Date;

/**
 * Created by Administrator on 2017/3/16.
 */
public class MyThread extends Thread {
    private Date createDate;
    private Date startDate;
    private Date finishDate;
    public MyThread(Runnable r,String name){
        super(r,name);
        createDate=new Date();
    }

    @Override
    public void run() {
        startDate=new Date();
        super.run();
        finishDate=new Date();
    }

    public long getExecutionTime(){
        return finishDate.getTime()-startDate.getTime();
    }

    @Override
    public String toString() {
        StringBuilder buffer=new StringBuilder();
        buffer.append(getName());
        buffer.append(":");
        buffer.append("CreateDate:"+ MyDateUtils.getFormatStringInfo(createDate));
        buffer.append("Runtime:"+ getExecutionTime()+" Milliseconds");
        return buffer.toString();
    }
}
